﻿using System.Data;
using BusinessLogic.ClassFactory;
using Model.Data;

namespace BusinessLogic.BusinessRules
{
    /// <summary>
    /// ArtSecRelation 的摘要说明。
    /// </summary>
    public class ArtSecRelation : BaseClass
    {
        #region 必有属性

        public Model.Data.ArtSecRelationData.ArtSecRelationRow DataItem
        {
            get
            {
                return (Model.Data.ArtSecRelationData.ArtSecRelationRow)base.m_CurrentRow;
            }
            set
            {
                base.m_CurrentRow = value;
            }
        }

        private Model.Data.ArtSecRelationData m_Data
        {
            get
            {
                return (Model.Data.ArtSecRelationData)base.m_DataSet;
            }
            set
            {
                base.m_DataSet = value;
            }
        }

        public override int Count
        {
            get
            {
                return this.m_Data.ArtSecRelation.Count;
            }
        }

        #endregion 必有属性

        #region 构造函数

        public ArtSecRelation(DataAccess.DBManager m_DBManager, DataAccess.BaseAccess m_Access)
            : base(m_DBManager, m_Access)
        {
        }

        #endregion 构造函数

        #region 必须重载方法

        /// <summary>
        /// 根据数据集中索引,设置当前数据行
        /// </summary>
        /// <param name="n_index">数据集中的索引</param>
        public override void SelectRow(int n_index)
        {
            if (m_Data != null && m_Data.ArtSecRelation.Rows.Count > n_index)
            {
                DataItem = m_Data.ArtSecRelation[n_index];
            }
        }

        /// <summary>
        /// 实现更新
        /// </summary>
        /// <returns></returns>
        protected override int OnUpdate()
        {
            return m_Access.Update(this.m_DataSet);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        protected override bool OnDelete(int ID)
        {
            return true;
        }

        public override void NewDataSet()
        {
            this.m_Data = new ArtSecRelationData();
            m_CurrentRow = m_Data.ArtSecRelation.NewArtSecRelationRow();
        }

        public override void SetDataSet(DataSet m_DataSet)
        {
            this.m_DataSet = m_DataSet;
        }

        public override bool OnInsert()
        {
            this.DataItem.intSecArtID = this.GetNextSeed();
            this.m_Data.ArtSecRelation.Rows.Add(this.m_CurrentRow);
            return true;
        }

        /// <summary>
        /// 设置文章发布状态为已发布
        /// </summary>
        /// <param name="intSTID">栏目ID</param>
        /// <param name="IsIssue">是否已发布</param>
        public void SetArticleIssueStatus(int intSTID, bool IsIssue)
        {
            if (IsIssue)
            {
                SectionsFactory objFactory = new SectionsFactory(m_DBManger);
                objFactory.UpdateState(intSTID);
            }
        }

        #endregion 必须重载方法

        #region 业务属性

        public Model.Data.ArtSecRelationData Data
        {
            get
            {
                return (Model.Data.ArtSecRelationData)base.m_DataSet;
            }
            set
            {
                base.m_DataSet = value;
            }
        }

        #endregion 业务属性
    }
}